export const dragList = [
  {
    tag: 'button',
    name: '按钮'
  },
  {
    tag: 'image',
    name: '单图组件'
  },
  {
    tag: 'image_map',
    name: '一图片多链接'
  }
]

class MyButton {
  constructor(tag, name) {
    this.name = name
    this.tag = tag
    this.text = '立即查看'
    this.action = {
      data: {},
      type: 'none',
      route: false
    }
  }
}
class Myimage {
  constructor(tag, name) {
    this.name = name
    this.tag = tag
    this.src = import.meta.env.VITE_OSS_DOMAIN + '/cms/upload/demo/1.jpg'
    this.action = {
      data: {},
      type: 'none',
      route: false
    }
  }
}
class MyImageMap {
  constructor(tag, name) {
    this.name = name
    this.tag = tag
    this.src = import.meta.env.VITE_OSS_DOMAIN + '/cms/upload/demo/1.jpg'
    this.rows = 1
    this.columns = 2
    this.height = 200
    this.actions = [
      {
        action: {
          data: {},
          type: 'none',
          route: false
        }
      },
      {
        action: {
          data: {},
          type: 'none',
          route: false
        }
      }
    ]
  }
}

const constructors = {
  button: MyButton,
  image: Myimage,
  image_map: MyImageMap
}
export const getNewElement = (element) => {
  const Constructor = constructors[element.tag]
  if (!Constructor) {
    throw new Error(`No constructor found for tag: ${element.tag}`)
  }
  return new Constructor(element.tag, element.name)
}
